using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIBattlePlayerChat : UIObject
{
    public Text textChallenge;
    public GameObject rootObj;
    private DataBattlePlayer _dataBattlePlayer;

    protected override void Awake()
    {
        base.Awake();
        rootObj.SetActive(false);
    }
    public void Bind(DataBattlePlayer data)
    {
        _dataBattlePlayer = data;
        _dataBattlePlayer.OnPlayerChat += OnPlayerChat;
    }

    public void Unbind()
    {
        _dataBattlePlayer.OnPlayerChat -= OnPlayerChat;
        _dataBattlePlayer = null;
    }

    private void OnPlayerChat(string content)
    {
        CancelInvoke(nameof(HideRootObj));
        rootObj.SetActive(true);
        textChallenge.text = content;
        Invoke(nameof(HideRootObj), 3);
    }

    private void HideRootObj()
    {
        rootObj.SetActive(false);
    }
}
